let loaded = false

export const loadBMap = () =>
    new Promise((resolve, reject) => {
            if (loaded || window.BMapGL) {
                    loaded = true
                    resolve()
                    return
            }

            const script = document.createElement('script')
            script.type = 'text/javascript'
            script.src =
                'https://api.map.baidu.com/api?type=webgl&v=1.0&ak=ZFFYeb35z0tlgY64OfbtMfg9SV7KNxzW&callback=onBMapGLReady'
            document.head.appendChild(script)

            window.onBMapGLReady = () => {
                    loaded = true
                    resolve()
            }

            script.onerror = reject
    })